package com.funkids.prxis.controller;

import com.funkids.common.Result;
import com.funkids.rabbitmq.RMSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    BCryptPasswordEncoder bCryptPasswordEncoder;

    @Autowired
    RMSender rmSender;


    @GetMapping("/encode")
    public Result encode(){
        String password = bCryptPasswordEncoder.encode("hugh@2ys");
        boolean matches = bCryptPasswordEncoder.matches("hugh@2ys", password);

        System.out.println(matches);
        return Result.succ(password);
    }

    @PreAuthorize("hasRole('admin')")
    @GetMapping("/admin")
    public Result adminTest(){
        return Result.succ("欢迎管理员!");
    }

    @PreAuthorize("hasAuthority('sys:role:list')")
    @GetMapping("/list")
    public Result adminTest2(){
        return Result.succ("欢迎管理员2!");
    }

    @PostMapping("/mq")
    public Result send(){
        rmSender.send("一条消息");
        return Result.succ("普通消息");
    }

//    @PostMapping("/mq/red")
//    public Result sendRed(){
//        rmSender.sendDirec2("一条红色消息");
//        return Result.succ("红色消息");
//    }
//
//    @PostMapping("/mq/blue")
//    public Result sendBlue(){
//        rmSender.sendDirec1("一条蓝色消息");
//        return Result.succ("蓝色消息");
//    }


}
